{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e3a76924-7fb2-41a2-8971-0e763a2713e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n",
      "45\n",
      "[12 15 18]\n",
      "[ 6 15 24]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "n=np.array([[1,2,3],[4,5,6],[7,8,9]])\n",
    "print(n)\n",
    "print(n.sum())  # 整个数组求和\n",
    "# 数据元素行的和\n",
    "print(n.sum(axis=0))\n",
    "# 列的和\n",
    "print(n.sum(axis=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "feaa25e0-e9d1-4995-89d1-61ed6c76bf15",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.0\n"
     ]
    }
   ],
   "source": [
    "# 平均值\n",
    "print(n.mean())\n",
    "# 行的平均值\n",
    "print(n.mean(axis=0))\n",
    "# 列的平均值\n",
    "print(n.mean(axis=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ca06029-1cdd-490b-95a6-0e3e9078fff1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数组当中的最大值和最小值\n",
    "print(n.max())\n",
    "print(n.min())\n",
    "# 行的最大值\n",
    "print(n.max(axis=0))\n",
    "# 行的最小值\n",
    "print(n.min(axis=0))\n",
    "# 列同理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "830e2960-99b6-477f-96a0-076fe7564a5c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.6666666666666665\n"
     ]
    }
   ],
   "source": [
    "#  加权平均\n",
    "# 一组数据与出现的次数相乘再平均计算，加权平均\n",
    "n1=np.array([1,2,3,4,5])  # 数组中的数据\n",
    "n2=np.array([10, 20, 30, 40, 50]) # n2表示n1数组中数据出现的次数\n",
    "print(np.average(n1, weights=n2))  # （1*10+2*20+3*30+4*40+5*50）/(10+20+30+40+50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ccee9d51-e40f-4299-8e56-d27ac057f3ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.5\n"
     ]
    }
   ],
   "source": [
    "# 中位数 前提是数组有序\n",
    "n1=np.array([1,2,3,4,5,6]) # (3+4)/2\n",
    "print(np.median(n1))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6fac1d2e-5575-495c-895b-13987ee8f084",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.6666666666666666\n"
     ]
    }
   ],
   "source": [
    "# 方差：各种数据与它们的平均数的平方\n",
    "n=np.array([1, 2, 3]) # 平均数=2 （1-2）= -1  （2-2）=0  （3-2）=1 \n",
    "print(n.var())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "61f4d51b-f625-42a2-b076-1841d489232d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.816496580927726\n"
     ]
    }
   ],
   "source": [
    "# 标准差 被称为方差的平方根\n",
    "print(n.std())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
